<?php

class COrderItem extends Zend_Db_Table{
	
	protected $_name;
	
	protected $_primary;

	
	public function _setup(){
		
		$this->_name=R_PRE."order_item";
		
		//$this->_primary="contactid";
		
		parent::_setup();
		
	}

	
	public function createOrderItem($data){
		
		$this->insert($data);
		
	}
	
	public function editOrderItem($orderid,$itemid,$data){
		
		$db=$this->getAdapter();
		
		$where = $db->quoteInto('orderid = ?', $orderid).
				' AND '.$db->quoteInto('itemid = ?', $itemid);

		$rows_affected=$db->update($this->_name,$data,$where);
		
		if($rows_affected!=1){
			
			return false;
			
		}else{
			
			return true;
			
		}
		
		
	}
	
	public function getDetail($orderid,$itemid){

            if(!$itemid)
            {
                $itemid=0;
            }
		
		$db=$this->getAdapter();
		
		$select = $db->select();
		
		$select->from($this->_name,'*');	
		
		$select->where('orderid = ? ',$orderid);
		
		$select->where('itemid = ? ',$itemid);
		
		return $db->fetchAll($select);
		
	}
	
	public function delOrderItem($orderid,$itemid){
		
		$db=$this->getAdapter();
		
		$where = $db->quoteInto('orderid = ?', $orderid).
				$db->quoteInto('itemid = ?', $itemid);
		
		$result=$db->delete($this->_name,$where);
		
		return $result;
		
	}
	
	public function getOrderItems($orderid,$where=''){
		
		$db=$this->getAdapter();
		
		$select = $db->select();
		
		$select->from($this->_name,'*');
		
		$select->where('orderid = ?', $orderid);
		
		if($where!=''){
			
			$select->where($where);
			
		}
		
		return $db->fetchAll($select);
		
	}
	
	public function getOrderItemCounts($orderid,$where=''){
		
		$db=$this->getAdapter();
		
		$select = $db->select();
		
		$select->from($this->_name,'COUNT(*)');
		
		$select->where('orderid = ?', $orderid);
		
		if($where!=''){
			
			$select->where($where);
			
		}
		
		return $db->fetchOne($select);
		
	}

	/*
	public function getAllOrderItem($orderid,$where=''){
		
		$db=$this->getAdapter();
		
		$orderTable=R_PRE.'items';
		
		$select = $db->select();
		
		$select->from($this->_name,'*');
		
		if($uid!=0&&$uid!=''){
			
			$select->where($itemTable.'.uid = ? ',$uid);
			
		}
		

		
		if($where!=''){
			
			$select->where($where);
			
		}
		
		$select->order("$itemTable.contactid DESC");
		
		if($counts!=0){
		
			$select->limit($counts, $from);
		
		}
		
		return $db->fetchAll($select);
		
	}
*/
	

	
}